﻿using System;
using System.Collections.Generic;

namespace BizElements.BusinessLayer
{
    /// <summary>Readonly wrapper for another IDataObjectDescriptor instance.</summary>
    public class DataObjectDescriptorWrapper : IDataObjectDescriptor
    {
        /// <summary>Wrapped instance whose properties are exposed through read-only properties that belong to this class.</summary>
        protected IDataObjectDescriptor WrappedInstance { get; private set; }

        #region CTor.

        /// <summary>Initializes a new instance of <b>DataObjectDescriptorWrapper</b> class.</summary>
        /// <param name="wrappedInstance">Instace to wrap by new object.</param>
        protected DataObjectDescriptorWrapper(IDataObjectDescriptor wrappedInstance)
        {
            this.WrappedInstance = wrappedInstance;
        }

        #endregion

        #region IDataObjectDescriptor properties.

        /// <summary>Map of special entity properties such as ownership fields, audit fields etc. These fields affect various aspects of data, business and UI logic.</summary>
        public FieldMap Fields { get { return this.WrappedInstance.Fields; } }

        /// <summary>Optional field-level security access permissions. Empty collection if no special field-level access permissions are defined.</summary>
        public IEnumerable<FieldPermissionSet> FieldPermissions { get { return this.WrappedInstance.FieldPermissions; } }

        #endregion

        #region FieldMap - exposed properties.

        /// <summary>Name of optional property that indicates whether the record is active (1) or deactivated/deleted (0).</summary>
        public string StatusPropertyName { get { return this.WrappedInstance.Fields.StatusPropertyName; } }

        /// <summary>Name of, typically textual, default property for user interface.</summary>
        public string DefaultPropertyName { get { return this.WrappedInstance.Fields.DefaultPropertyName; } }
        /// <summary>Optional name of default property by which entities are sorted in collections.</summary>
        public string OrderByPropertyName { get { return this.WrappedInstance.Fields.OrderByPropertyName; } }

        /// <summary>Name of optional logging property that contains username of actor that created the entity.</summary>
        public string CreatedByPropertyName { get { return this.WrappedInstance.Fields.CreatedByPropertyName; } }
        /// <summary>Name of optional date-time property that contains entity creation timestamp.</summary>
        public string CreatedOnPropertyName { get { return this.WrappedInstance.Fields.CreatedOnPropertyName; } }
        /// <summary>Name of optional logging property that contains username of actor that was last to update the entity.</summary>
        public string UpdatedByPropertyName { get { return this.WrappedInstance.Fields.UpdatedByPropertyName; } }
        /// <summary>Name of optional date-time property that contains last modification timestamp.</summary>
        public string UpdatedOnPropertyName { get { return this.WrappedInstance.Fields.UpdatedOnPropertyName; } }

        /// <summary>Names of properties used by optimistic offline concurrency control scheme to check if another user or process has changed the object.
        /// Can be same as <see cref="UpdatedOnPropertyName"/> but it may also be a dedicated timestamp/row-version field or even all of the entity fields.
        /// Empty array or <b>null</b> if optimistic offline locking scheme is not used.</summary>
        public string[] ChangeTrackingPropertyNames { get { return this.WrappedInstance.Fields.ChangeTrackingPropertyNames; } }

        /// <summary>Name of optional property that contains a reference to actor/user that owns the entity.</summary>
        public string OwnerIdPropertyName { get { return this.WrappedInstance.Fields.OwnerIdPropertyName; } }
        /// <summary>Name of optional property that contains a reference to a team of users that work on entity.</summary>
        public string TeamIdPropertyName { get { return this.WrappedInstance.Fields.TeamIdPropertyName; } }
        /// <summary>Name of optional property that contains a reference to an organisational unit that owns the entity.</summary>
        public string UnitIdPropertyName { get { return this.WrappedInstance.Fields.UnitIdPropertyName; } }
        /// <summary>Name of optional property that contains a reference to an organization that owns the entity.</summary>
        public string OrganizationIdPropertyName { get { return this.WrappedInstance.Fields.OrganizationIdPropertyName; } }

        /// <summary>Name of optional property that determines business object subtype, i.e. derived class. 
        /// The values stored in this field are typically used by factory classes to build instances derived concrete classes.</summary>
        public string SubtypeIdPropertyName { get { return this.WrappedInstance.Fields.SubtypeIdPropertyName; } }

        #endregion
    }    
}
